/**
 * 通用方法封装处理
 * Copyright (c) 2018 ruoyi
 */

$(function() {
    $.extend({
        snowUtils:{
            // 空格截取
            trim: function (value) {
                if (value == null) {
                    return "";
                }
                return value.toString().replace(/(^\s*)|(\s*$)|\r|\n/g, "");
            },
            // 判断字符串是否为空
            isEmpty: function (value) {
                if (value == null || this.trim(value) == "") {
                    return true;
                }
                return false;
            },
            //值转换为xml可显示的编码
            //https://www.cnblogs.com/xiaoleiel/p/8308774.html
            htmlEncode:function(str)
            {
                if(this.isEmpty(str)){
                    return "";
                }
                var s = "";
                if (str.length == 0) return "";
                s = str.replace(/&/g, "&amp;");
                s = s.replace(/</g, "&lt;");
                s = s.replace(/>/g, "&gt;");
                s = s.replace(/ /g, "&nbsp;");
                s = s.replace(/\'/g, "&#39;");
                s = s.replace(/\"/g, "&quot;");
                // s = s.replace(/\n/g, "");
                s = s.replace(/\n/g, "&#10;");
                return s;
            }
        }
    });
});




